package team.pwy.controller;


import com.github.pagehelper.PageInfo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import team.pwy.pojo.entity.Coupon;
import team.pwy.service.CouponService;
import team.pwy.vo.Result;

import java.util.List;

@RestController
@RequestMapping("coupon")
public class CouponController {
    @Autowired
    private CouponService couponService;
    @Autowired
    private RabbitTemplate rabbitTemplate;



    @GetMapping("/findByUserId")
    public Result findByUserId(Integer userId,Integer pageNum,Integer pageSize) {
        PageInfo<Coupon> couponList = couponService.findByUserId(userId,pageNum,pageSize);
        if (couponList != null && couponList.getList().size() != 0){
            return new Result("200", "查询成功", couponList);
        }
        return new Result("400", "没有优惠卷",couponList);

    }

    @PostMapping("/delById/{id}")
    public Result delById(@PathVariable("id") Integer id) {
        Integer count = couponService.delById(id);
        return count != 0 ? new Result("200", "删除成功") : new Result("400", "删除失败");
    }

    @GetMapping
    public Result findByUserIdStatus(Integer userId, Integer status,Integer pageNum,Integer pageSize) {
        PageInfo<Coupon> couponList = couponService.findByUserIdStatus(userId, status, pageNum, pageSize);
        if (couponList.getTotal() != 0){
            System.out.println(couponList);
            return new Result("200", "查询成功", couponList);
        }
        return new Result("400", "查询失败");
    }
}
